<script language="javascript">
    $().ready(function() {
        // validar formulario del cliente
        $("#editDepartamentForm").validate({
            rules: {
                name: "required",
                id_user: "required"
            },
            messages: {
                name: "Ingrese el nombre",
                id_user: "Seleccione un encargado."
            }
        });
    } );
</script>

<article class="module width_full">
    <header><h3>Editar Departamento</h3></header>
    <div class="module_content">
        <form style="width: 600px;" class="cmxform" method="post" id="editDepartamentForm" action="<?php echo $this->url(); ?>">
            <p>
                <label for="name">Nombre *</label>
                <input name="name" id="name" value="<?php echo $this->departament->name; ?>"/>
            </p>
            <p>
                <label for="description">Descripcion</label>
                <textarea name="description" id="description"><?php echo $this->departament->description; ?></textarea>
            </p>
            <p>
                <label for="id_user">Encargado</label>
                <!-- // aqui tenemos que iterar todos los usuarios. -->
                <select id="id_user" name="id_user">
                    <option>-- Seleccione un encargado --</option>
                    
                    <?php foreach ($this->users as $user) :?>
                    <?php
                        if ($this->departament->id_user == $user->id)
                            $sel = 'selected="selected"';
                        else
                            $sel = '';
                        ?>
                    <option value="<?php echo $user->id; ?>" <?php echo $sel; ?>><?php echo $user->nombre.' '.$user->apellidos; ?></option>
                    <?php endforeach; ?>
                </select>
            </p>

            <div class="submit_link">
                <input type="submit" value="Guardar" class="alt_btn"/>
                <a class="button" href="<?php echo $this->url(array('action' => 'index', 'id' => null)) ?>">Close</a>
            </div>
        </form>
    </div>
    <footer></footer>
</article>